package com.xinsilu.ceshi.controller;


import com.xinsilu.ceshi.entity.Ceshi;
import com.xinsilu.ceshi.service.ICeshiService;
import com.xinsilu.common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author ym
 * @since 2021-09-09
 */
@RestController
@CrossOrigin   //解决跨域
@RequestMapping("/api/vi/ceshi")
public class CeshiController {

    @Autowired
    private ICeshiService iCeshiService;

    @RequestMapping("/getList")
    public Object getList() {

        List<Ceshi> list = iCeshiService.list(null);
        return Result.ok(list);
    }

    @RequestMapping("/add")
    public Object add(Ceshi ceshi) {
        boolean count = iCeshiService.save(ceshi);
        if (count) {
            return Result.ok("新增成功");
        }
        return Result.ok("异常");

    }

    @RequestMapping("/getId")
    public Object getId(int id) {
        Ceshi byId = iCeshiService.getById(id);
        return Result.ok(byId);
    }

    @RequestMapping("/update")
    public Object update(Ceshi ceshi) {
        boolean b = iCeshiService.updateById(ceshi);
        if (b) {
            return Result.ok("修改成功");
        }
        return Result.ok("修改失败");
    }

    @RequestMapping("/delect")
    public Object delect(int id) {
        boolean b = iCeshiService.removeById(id);
        if (b) {
            return Result.ok("删除成功");
        }
        return Result.ok("删除失败");
    }
}
